package com.wanmait.recruit.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.pojo.SkillLabel;
import com.wanmait.recruit.service.SkillLabelService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@Transactional
@RequestMapping("/manage/skillLabel")
public class SkillLabelController {
    @Resource
    private SkillLabelService skillLabelService;
    @RequestMapping("skillLabelList")
    public void skillLabelList(){

    }
    @RequestMapping("skillLabelListData")
    public ModelAndView skillLabelListData(String name,Integer pageNum){
        ModelAndView modelAndView = new ModelAndView();
        PageInfo<SkillLabel> pageInfo = skillLabelService.findAllByName(name, pageNum);
        modelAndView.addObject("pageInfo",pageInfo);
        modelAndView.setViewName("/manage/skillLabel/skillLabelListData");
        return modelAndView;
    }
    @RequestMapping("insert")
    public void insert(){

    }
    @PostMapping("insert")
    public String insert(String skillLabelName){
        SkillLabel skillLabel = new SkillLabel();
        skillLabel.setSkillLabelName(skillLabelName);
        skillLabelService.insert(skillLabel);
        return "redirect:/manage/skillLabel/insert";
    }
    @RequestMapping("delete")
    public String delete(Integer id){
        skillLabelService.deleteById(id);
        return "redirect:/manage/skillLabel/skillLabelList";
    }
    @RequestMapping("isRename")
    @ResponseBody
    public String isRename(String skillLabelName){
        Boolean flag = skillLabelService.isRename(skillLabelName);
        if(flag){
            return "1";
        }else{
            return "0";
        }
    }
}
